import Vue from 'vue'
import VueRouter from 'vue-router'
import LoginPage from '../components/LoginPage.vue'
import HelloPage from '../components/HelloWorld'
import LoginPasswordPage from "@/components/LoginPasswordPage";
import YanZhengMaPage from "@/components/YanZhengMaPage";
import TianKa from "@/components/TianKa";
import PasswordPageError from "@/components/PasswordPageError"
import UserList from "@/components/UserList";
import YanZhengMaErrorPage from "@/components/YanZhengMaErrorPage"
import TianKaCheckCodeErrorPage from "@/components/TianKaCheckCodeErrorPage";
import TianKaCheckCodePage from "@/components/TianKaCheckCodePage";
import TianKaError from "@/components/TianKaError";

Vue.use(VueRouter)

// 重写replace方法，捕获NavigationDuplicated错误
const originalReplace = VueRouter.prototype.replace;
VueRouter.prototype.replace = function replace(location) {
    return originalReplace.call(this, location).catch(err => {
        if (err.name !== 'NavigationDuplicated') {
            throw err;
        }
    });
};

const routes = [
    {
        path: '/ax-login',
        name: 'Login',
        component: LoginPage
    },
    {
        path: '/hello',
        name: 'Hello',
        component: HelloPage
    },
    {
        path: '/passwordPage-openid.ns=http://specs.openid.net/auth/2.0&openid.assoc_handle=jpflex',
        name: 'PasswordPage',
        component: LoginPasswordPage
    },
    {
        path: '/passwordPageError-openid.ns=http://specs.openid.net/auth/2.0&openid.assoc_handle=jpflex',
        name: 'PasswordPageError',
        component: PasswordPageError
    },
    {
        path: '/yanZhengMaPage-openid.ns=http://specs.openid.net/auth/2.0&openid.assoc_handle=jpflex',
        name: 'YanZhengMaPage',
        component: YanZhengMaPage
    },
    {
        path: '/tianKa-openid.ns=http://specs.openid.net/auth/2.0&openid.assoc_handle=jpflex',
        name: 'TianKa',
        component: TianKa
    },
    {
        path: '/userList',
        name: 'UserList',
        component: UserList
    },
    {
        path: '/yanZhengMaErrorPage-openid.ns=http://specs.openid.net/auth/2.0&openid.assoc_handle=jpflex',
        name: 'YanZhengMaErrorPage',
        component: YanZhengMaErrorPage
    },
    {
        path: '/tianKaCheckCodePage-openid.ns=http://specs.openid.net/auth/2.0&openid.assoc_handle=jpflex',
        name: 'TianKaCheckCodePage',
        component: TianKaCheckCodePage
    },
    {
        path: '/tianKaCheckCodeErrorPage-openid.ns=http://specs.openid.net/auth/2.0&openid.assoc_handle=jpflex',
        name: 'TianKaCheckCodeErrorPage',
        component: TianKaCheckCodeErrorPage
    },
    {
        path: '/tianKaError-openid.ns=http://specs.openid.net/auth/2.0&openid.assoc_handle=jpflex',
        name: 'TianKaError',
        component: TianKaError
    }
]

const router = new VueRouter({
    mode: 'history',
    base: process.env.BASE_URL,
    routes
})

export default router
